export default {
  namespaced: true,
  state: {
    // 菜单列表
    menuList: [],
  },
  mutations: {
    /**
     * @description 设置顶栏菜单
     * @param {Object} state vuex state
     * @param {Array} menu menu setting
     */
    menuSet(state, menu) {
      // store 赋值
      state.menuList = menu;
    },
  },
  actions: {
    /**
     * 初始化菜单
     * @param {Array} menu tree
     * add by lss
     */
    // eslint-disable-next-line no-unused-vars
    initMenu({ state, dispatch, commit }, menu) {
      commit('menuSet', menu);
      dispatch(
        'vxadmin/db/set',
        {
          dbName: 'sys',
          path: 'menu.menuTree',
          value: menu,
          user: true,
        },
        { root: true },
      );
    },
    /**
     * 从持久化数据中恢复菜单
     * add by lss
     */
    loadMenu({ dispatch }) {
      return dispatch(
        'vxadmin/db/get',
        {
          dbName: 'sys',
          path: 'menu.menuTree',
          user: true,
        },
        { root: true },
      );
    },
  },
};
